package gsm.cable.client.view;

import gsm.cable.client.DefaultConstants;
import gsm.cable.client.css.StylesheetConstants;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.VerticalAlign;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;

public class HeaderWidget extends HorizontalPanel {

	public HeaderWidget() {
		setHeight(DefaultConstants.HEADER_HEIGHT + "px");
		setStyleName(StylesheetConstants.APP_HEADER_PANEL);
		addStyleName(StylesheetConstants.APP_HEADER_TITLE_CONTAINER);
	}

	public void setOrganizationLogo(String imageUrl) {
		if (imageUrl != null && imageUrl.trim().length() > 0) {
			Image organizationLogo = new Image();
			organizationLogo.setPixelSize(DefaultConstants.ORGANIZATION_LOGO_WIDTH, DefaultConstants.ORGANIZATION_LOGO_HEIGHT);
			add(organizationLogo);
			getChildren().get(getWidgetCount() - 1).getElement().getParentElement().getStyle().setWidth(DefaultConstants.ORGANIZATION_LOGO_WIDTH, Unit.PX);
			organizationLogo.setUrl(imageUrl);
		}
	}

	public void addOrganizationTitle(String title, String slogan) {
		HTML organizationTitle = new HTML(title);
		organizationTitle.addStyleName(StylesheetConstants.APP_HEADER_ORGANIZATION_TITLE);
		if (slogan != null && slogan.trim().length() > 0) {
			VerticalPanel titlePanel = new VerticalPanel();
			titlePanel.setVerticalAlignment(ALIGN_MIDDLE);
			titlePanel.add(organizationTitle);

			HTML organizationSlogan = new HTML(slogan);
			titlePanel.add(organizationSlogan);
			organizationSlogan.addStyleName(StylesheetConstants.APP_HEADER_ORGANIZATION_SLOGAN);
			add(titlePanel);
		} else {
			add(organizationTitle);
		}
		getChildren().get(getWidgetCount() - 1).getElement().getParentElement().getStyle().setVerticalAlign(VerticalAlign.MIDDLE);
	}
}
